﻿Imports System.Windows.Forms
Public Class ucSup
    Private SupplierID As Integer
    Public Function ucValidateSupp() As Boolean
        If txtSuppName.Text.Length = 0 Or txtAdd.Text.Length = 0 Or txtEmail.Text.Length = 0 Or txtPhone.Text.Length = 0 Or rtxtOtherInfo.Text.Length = 0 Then
            MessageBox.Show("Bạn vui lòng nhập đầy đủ thông tin!")
            txtSuppName.Focus()
            Return False
        End If
        If txtEmail.Text Like "*@[A-Z,a-z,0-9]*.*" Then
            Return True
        Else
            MessageBox.Show("Email không đúng định dạng!")
            txtEmail.Text = ""
            txtEmail.Focus()
            Return False
        End If
        If txtPhone.Text Like "[0-9]" Then
            Return True
        Else
            MessageBox.Show("Số điện thoại không đúng định dạng!")
            txtPhone.Text = ""
            txtPhone.Focus()
            Return False
        End If
        Return True
    End Function
    Public Sub SetSupplier(ByVal supplier As eSupplier)
        txtAdd.Text = supplier.Address
        txtEmail.Text = supplier.Email
        txtPhone.Text = supplier.Phone
        txtSuppName.Text = supplier.SupplierName
        rtxtOtherInfo.Text = supplier.OtherInfo
        SupplierID = supplier.SupplierID
    End Sub
    Public Function GetSupplier() As eSupplier
        Dim supplier As eSupplier = New eSupplier()
        If (ucValidateSupp()) Then
            supplier.SupplierName = txtSuppName.Text
            supplier.Phone = txtPhone.Text
            supplier.Email = txtEmail.Text
            supplier.Address = txtAdd.Text
            supplier.OtherInfo = rtxtOtherInfo.Text
            supplier.SupplierID = SupplierID
            Return supplier
        Else
            Return Nothing
        End If
    End Function
    Public Sub ClearText()
        For Each c As Control In grpSupplier.Controls
            If (TypeOf c Is TextBox Or TypeOf c Is RichTextBox) Then
                c.ResetText()
            End If
        Next
    End Sub
End Class
